package com.duoma.view.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.duoma.view.R;

public class AnimFrameActivity extends AppCompatActivity {

    private AnimationDrawable mAnimationDrawable;

    public static void start(Context context) {
        Intent intent = new Intent(context, AnimFrameActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_anim_frame);

        initUi();
    }

    private void initUi() {

        ImageView image = (ImageView) findViewById(R.id.imageView);
        image.setImageResource(R.drawable.drawable_animation_robot);
        mAnimationDrawable = (AnimationDrawable) image.getDrawable();

        findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mAnimationDrawable.start();
            }
        });

        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mAnimationDrawable.stop();
            }
        });
    }
}
